package cn.lingyangwl.agile.pay.common.assembly;

import cn.lingyangwl.framework.tool.core.StringUtils;
import cn.lingyangwl.agile.pay.model.rqrs.PayInterfaceConfigRQ;
import cn.lingyangwl.agile.pay.model.rqrs.PayInterfaceConfigRS;
import cn.lingyangwl.agile.pay.model.entity.PayInterfaceConfig;
import cn.lingyangwl.agile.pay.model.entity.PayInterfaceDefine;
import cn.lingyangwl.agile.pay.model.rqrs.PayInterfaceDefineRQ;
import com.alibaba.fastjson2.JSONArray;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

/**
 * @author shenguangyang
 */
@Mapper(componentModel = "spring")
public interface PayInterfaceAssembly {
    PayInterfaceConfig toPayInterfaceConfig(PayInterfaceConfigRQ source);

    PayInterfaceConfigRS toPayInterfaceConfigResp(PayInterfaceConfig source);

    @Mappings({
            @Mapping(source = "wayCodes", target = "wayCodes", qualifiedByName = "strToJSONArray"),
    })
    PayInterfaceDefine toPayInterfaceDefine(PayInterfaceDefineRQ req);

    @Named("strToJSONArray")
    default JSONArray strToJSONArray(String item) {
        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(StringUtils.toList(item, ",", String.class));
        return jsonArray;
    }
}
